package com.rmi;

/**
 * HelloApplet.java
 * 	An rmi user applet which calls Hello remote interface methods
 * @author Yoon Kyung Koo (yoonforh@moon.daewoo.co.kr)
 * @version 1.0 1999/05/09
 */
import java.rmi.*;
import java.applet.Applet;
import java.awt.*;

public class HelloApplet extends Applet {
	String message = null;
	public void init() {
		try {
			/**
	If you are using an applet that uses RMI callbacks, you must call
	netscape.security.PrivilegeManager.enablePrivilege("UniversalConnect");
	before the your first call into the RMI runtime. 
			 */
			// netscape package is included within %NETSCAPE%\Program\java\classes\java40.jar
			try {
				// netscape.security.PrivilegeManager.enablePrivilege("UniversalConnect"); 
				Class mgr = Class.forName("netscape.security.PrivilegeManager");
				Class[] classes=new Class[1];
				classes[0]=String.class;
				java.lang.reflect.Method method =
					mgr.getMethod("enablePrivilege", classes);
				Object[] args=new Object[1];
				args[0]="UniversalConnect";
				method.invoke(null /*static method */, args);

			}
			catch (Exception e) { e.printStackTrace(); }
			String url = "rmi://" + getCodeBase().getHost()
				+ "/HelloServer";
			// DEBUG
			System.out.println("url is "+url);
			Hello obj =
				(Hello) Naming.lookup(url);
			message = "HelloServer said \""+obj.hello()+'"';
		} catch (Exception e) {
			message = "Error:"+e.toString();
		}
	}
	public void paint(Graphics g) {
		if (message != null) {
			g.setFont(new Font("SansSerif", Font.BOLD, 20));
			g.drawString(message, 10, 100);
		}
	}
}